home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / asm_n_z.arj / TSRPARK.ASM < prev    next >
Assembly Source File  |  1988-07-18  |  21KB  |  485 lines

  1.         PAGE 60,120
  2.         TITLE TSRPARK.ASM -- TesSeRact Demo program to park disk drive heads
  3. ;----------------------------------------------------------------------------
  4. SUBTTL  Originally TESSPARK.ASM : TesSeRact Revision Level 1
  5. ;-----------------------------------------------------------------------------
  6. ;   TesSeRact(tm) -- A Library of Routines for Creating Ram-Resident (TSR)
  7. ;                    programs for the IBM PC and compatible Personal
  8. ;                    Computers.
  9. ;
  10. ;The software, documentation and source code are:
  11. ;
  12. ;       Copyright (C) 1986, 1987, 1988 Tesseract Development Team
  13. ;       All Rights Reserved
  14. ;
  15. ;       c/o Chip Rabinowitz
  16. ;       Innovative Data Concepts
  17. ;       2084 Woodlawn Avenue
  18. ;       Glenside, PA 19038
  19. ;       1-215-884-3373
  20. ;
  21. ;-----------------------------------------------------------------------------
  22. ;   This product supports the TesSeRact Standard for Ram-Resident Program
  23. ;   Communication.  For information about TesSeRact, contact the TesSeRact
  24. ;   Development Team at:
  25. ;       Compuserve:    70731,20
  26. ;       MCIMAIL:       315-5415
  27. ;   This MCIMAIL Account has been provided to the TesSeRact Development
  28. ;   Team by Borland International, Inc.  The TesSeRact Development Team
  29. ;   is in no way associated with Borland International, Inc.
  30. ;-----------------------------------------------------------------------------
  31. ;
  32. ; BASED on code originally provided by Jim Mischel
  33. ;
  34. ; ORIGINAL COPYRIGHT NOTICE:
  35. ;
  36. ;;;; AUTOPARK.ASM - program to automatically park the disk drive heads
  37. ;;;; at specified time intervals.
  38. ;;;;
  39. ;;;; Copyright (c) 1988, Jim Mischel
  40. ;;;;
  41. ;;;; This program has been assembled using MASM 5.0.  Changes may be required
  42. ;;;; for use with earlier versions.
  43. ;;;;
  44.  
  45. ;;;;;                 TSRPARK.ASM -  Rick Housh
  46. ;;;;;
  47. ;;;;; TSRPARK.ASM - Modifications to TESSPARK.ASM to allow variable timing
  48. ;;;;; intervals from 1 to 9 minutes for autopark with use of numerical
  49. ;;;;; parameter on command line, to support manual parking with use
  50. ;;;;; of hotkey, with popup when on DOS command line, detection of
  51. ;;;;; park failure on installation, and communication with the resident
  52. ;;;;; program to allow dynamically changing the elapsed time between
  53. ;;;;; automatic parks.  Assembled using MASM 5.1.
  54. ;;;;;
  55. ;;;;; Everything is self-explanatory, except perhaps how to reset the
  56. ;;;;; timer when resident.  Just enter ' TSRPARK # ', where # is any number
  57. ;;;;; of minutes between 1 and 9, and the new value will be inserted in the
  58. ;;;;; resident portion of the program.  A message will confirm the change
  59. ;;;;; and even the MAPMEM display of residents will show the new value.
  60. ;;;;; Entering ' TSRPARK ' with no parameter will yield a confirming message
  61. ;;;;; if TSRPARK is resident, and an instructional message if it has not
  62. ;;;;; yet been installed.  When the hotkey is pressed from the DOS prompt
  63. ;;;;; a message is displayed, in addition to the TESSBEEP sound.  Inside
  64. ;;;;; a program, the sound will occur, but there will be no message.
  65. ;;;;;
  66. ;;;;; I have changed the "mysterious" headparking code somewhat, and tried
  67. ;;;;; to expand the comments to show how it really works.  It's not that
  68. ;;;;; complicated, and does NOT care whether the computer is an AT or not,
  69. ;;;;; contrary to the comments in the original TESSPARK.  I have also found
  70. ;;;;; an undocumented and useful function.  Tch, tch.  TSRCHECKRESIDENT
  71. ;;;;; returns the segment of the resident program in the es register if
  72. ;;;;; it has found the program installed in memory.  The documentation
  73. ;;;;; only mentions a result returned in the ax register.  I found this
  74. ;;;;; very useful, and have implemented in TSRPARK.
  75. ;;;;;
  76. ;;;;; TSRPARK Modifications of TESSPARK, Rick Housh, CIS 72466,212 - 7/18/1988
  77. ;;;;;
  78.  
  79. ;;;;;
  80. ;;;;; To assemble this TesSeRact version:
  81. ;;;;;
  82. ;;;;;       MASM TSRPARK;
  83. ;;;;;       LINK TESS_ASM + TESS_BP + TSRPARK + TESS_END,TSRPARK;
  84. ;;;;;       EXE2BIN TSRPARK.EXE TSRPARK.COM
  85. ;;;;;
  86.  
  87. .model small
  88.  
  89. .code
  90.  
  91. ;
  92. ; Ticks2wait is # of timer ticks to wait between the last disk access
  93. ; and parking the disk.  There are approximately 18.2 ticks per second.
  94. ;
  95. ; Maximum possible ticks2wait is 65536 ticks, very close to 1 hour.
  96. ; Limit with this configuration is 9828 (9 minutes).
  97. ;
  98.  
  99. ticks_min       equ     1092            ;Number of timer ticks in 1 minute
  100. tinkle          equ     1               ;Sound TESSBEEP if set
  101.                                         ;set tinkle to 0
  102.                                         ;for no sound
  103. tick_count      dw      ?               ;Current count
  104. ticks2wait      dw      ?               ;Ticks to wait: 1092 = 1 minute
  105.  
  106. ;
  107. ; The parkit routine attempts to park all hard disks.
  108. ; Returns with carry set if park was unsuccessful.
  109. ;
  110. parkit  proc    near
  111.         mov     si,0080h                ;Hard drive id nos. start at 80h
  112. pk0:    mov     ah,08h                  ;Function gets drive parms.
  113.         mov     dx,si                   ;DX is drive ID No.
  114.         int     13h                     ;Get drive parms, dl = No. of drives
  115.         jc      pkdone                  ;Error if carry, jump out
  116.         xor     dh,dh                   ;Don't need max head-side number
  117.         mov     di,dx                   ;Save drive count from dl to di
  118.         cmp     di,01h                  ;Is there at least one?
  119.         jb      pkdone                  ;If no hard drives, exit
  120.         add     di,7fh                  ;Convert drive no. to drive id no.
  121.         inc     ch                      ;CH is now tracks + 1
  122.         jnb     pk1
  123.         add     cl,40h                  ;CL is sectors
  124. pk1:    mov     ax,0c01h                ;seek to cylinder
  125.         mov     dx,si                   ;DX is drive ID
  126.         int     13h                     ;this does the seek
  127.         inc     si                      ;bump drive count
  128.         cmp     si,di                   ;Was it the last? No? Then
  129.         jbe     pk0                     ;loop until all drives are parked
  130. pkdone:
  131. if tinkle
  132. EXTRN TESSBEEP:NEAR
  133.  
  134.         call    TESSBEEP
  135. endif
  136.         ret
  137. parkit  endp
  138.  
  139.  
  140. ;
  141. ; TesSeRact Entry Points
  142. ;
  143. ;
  144. PUBLIC  TSRUSERPROC, TSRTIMERPROC, TSRBACKCHECK, TSRMAIN, TSRBACKPROC
  145. PUBLIC  TSRCLEANUP
  146.  
  147. ;
  148. ; TSUSERPROC is a NULL procedure.  We don't service it in this program.
  149. ;
  150. ;
  151. TSRUSERPROC:                             ;Return, does nothing
  152.         ret
  153.  
  154. int13ptr        dw    0                  ;Saved location of INT 13 flag
  155.                                          ;  from TesSeRact data area
  156. do_park         db    0                  ;Flag set to 1 when wish to park
  157.  
  158. TSRminutes      db   " "                 ;Holds minutes between parks in ASCII
  159.  
  160. park_msg label near                      ;Message to display when popped up
  161.                                          ; AND at DOS prompt
  162.         db      13,10,10
  163.         db      'TSRPark has manually parked the hard disk(s)',13,10
  164.         db      'as requested.  Will automatically repark in ',13,10
  165.         db      '  minute(s) after next disk access.         ',13
  166. msg_len dw      $ - park_msg
  167.  
  168. reset_it   proc near
  169.         mov     do_park,0                ;Say not to park
  170.         mov     bx,[int13ptr]            ;Get INT13 flag
  171.         mov     byte ptr [bx],0          ;and turn off because
  172.                                          ;parking isn't using.
  173.         mov     ax,[ticks2wait]          ;Use our timer to
  174.         mov     [tick_count],ax          ;restart wait.
  175.  
  176.         ret
  177. reset_it   endp
  178.  
  179. TSRBACKCHECK proc near
  180.         assume cs:_TEXT, ds:_TEXT
  181.  
  182.         mov     al,do_park               ;Put flag in ax
  183.         xor     ah,ah                    ;if non-zero, call TSRBACKPROC
  184.         ret
  185. TSRBACKCHECK endp
  186.  
  187. TSRBACKPROC proc near
  188.         assume cs:_TEXT, ds:_TEXT
  189.  
  190.         call    parkit                   ;Attempt to park it
  191.         call    reset_it                 ;and reset everything
  192.  
  193.         ret
  194. TSRBACKPROC endp
  195.  
  196. TSRMAIN     proc near
  197.         assume cs:_TEXT, ds:_TEXT
  198.                                          ;On hotkey
  199.         call parkit                      ;Park disks
  200.         call reset_it                    ;and reset flags and timer
  201.         mov  ax,5453h                    ;TesSerAct function
  202.         mov  bx,16h                      ;to get InDos state
  203.         mov  cx,ParkNum                  ;This ident #
  204.         int  2fh                         ;Call function 16h
  205.         cmp  bx,1                        ;Check if at DOS prompt
  206.         jnz  mainX                       ;and end if not
  207.         mov  ah,08h                      ;First read attribute
  208.         mov  bh,0                        ;at current position
  209.         int  10h                         ;then
  210.         or   ah,08h                      ;turn on intensity bit
  211.         mov  bl,ah                       ;and save it in bl
  212.         mov  si,offset park_msg          ;Point to message
  213.         mov  cx,[msg_len]                ;and its length
  214. putmsg: lodsb                            ;Load ASCII character
  215.         cmp  al,20h                      ;Is it lower than space?
  216.         jb   no_att                      ;then don't paint attribute
  217.         push ax                          ;Save character
  218.         mov  ah,09h                      ;Paint an attribute
  219.         mov  al,20h                      ;with a space
  220.         sub  bh,bh                       ;on page zero
  221.         push cx                          ;Save count
  222.         mov  cx,1                        ;With this function
  223.         int  10h                         ;cursor doesn't move
  224.         pop  cx                          ;Restore character count
  225.         pop  ax                          ;and ASCII character
  226. no_att: mov  ah,0eh                      ;Set to print TTY
  227.         sub  bh,bh                       ;at page 0
  228.         int  10h                         ;and print characters
  229.         loop putmsg                      ;until end of string
  230.         mov  si,offset TSRminutes        ;Display minutes
  231.         lodsb                            ;Load a single character
  232.         int  10h                         ;and display it
  233.         mov  al,10                       ;Now a line feed
  234.         int  10h                         ;with TTY display
  235.         mov  ax,5453h                    ;TesSeRact function to
  236.         mov  cx,ParkNum                  ;Stuff a CR into
  237.         mov  bx,21h                      ;Keyboard Buffer
  238.         mov  di,Offset park_msg          ;Point to a 13
  239.         mov  si,1                        ;(one character).
  240.         mov  dx,0101h                    ;ASCII - medium speed
  241.         int  2fh                         ;call TesSerAct
  242.                                          ;DOS prompt should be back.
  243.                                          ;Can't correct error so no test.
  244. mainX:  ret
  245. TSRMAIN endp
  246.  
  247. TSRCLEANUP proc near
  248.         assume cs:_TEXT, ds:_TEXT
  249.  
  250.         or   ax,ax
  251.         jnz  clean_term
  252.  
  253. clean_init:
  254. ;
  255. ;  Please note that the data area returned by this function is also available
  256. ;    as the TESS_GLOBALS public symbol.
  257. ;
  258.         mov  cx,ParkNum                  ;This program's ID num.
  259.         mov  bx,4h                       ;in data area
  260.         mov  ax,5453h                    ;Ready for multiplex
  261.         int  2fh                         ;Call it, then point bx to
  262.         add  bx,3h                       ;offset of TesSerAct flag "Was13"
  263.         mov  int13ptr,bx                 ;and put in local pointer
  264.                                          ;Since program owns segment
  265.                                          ;no need to worry about it!
  266. clean_term:                              ;Nothing needed to terminate!
  267. clean_out:
  268.         ret
  269. TSRCLEANUP endp
  270.  
  271. TSRTIMERPROC proc near
  272.         assume cs:_TEXT, ds:_TEXT
  273.  
  274.         mov  bx,[int13ptr]               ;Check to see if
  275.         cmp  byte ptr [bx],1             ;disk has been accessed
  276.         jne  no_park                     ;since last parked
  277. no_disk:
  278.         mov  [do_park],0                 ;If no access, set park flag off
  279.         dec  [tick_count]                ;decrement the timer
  280.         jnz  no_park                     ;and exit
  281.         mov  [do_park],1                 ;else set park flag on
  282. clear_it:
  283.         mov  ax,[ticks2wait]             ;Use our own parameter
  284.         mov  [tick_count],ax             ;to restart wait
  285.         mov  byte ptr [bx],0             ;and clear flag
  286. no_park:
  287.         ret
  288.  
  289. TSRTIMERPROC endp
  290.  
  291. ; If AUTOPARK already installed, display error message and exit.
  292. ; If not installed, attempt to park the disks and install the resident
  293. ; portion.
  294. ;
  295. EXTRN TSDOINIT:NEAR
  296. EXTRN TSCHECKRESIDENT:near
  297. EXTRN TSSETSTACK:near
  298.  
  299. ParkNum      dw 0                        ;This ID number
  300. ParkName     db 'TSRPARK ',0             ;This Identification string
  301.  
  302. public topstack
  303.              db 48 dup('Back_Gnd')       ;BackProcStack - 384 bytes
  304.              db 48 dup('TSR_Main')       ;MainProcStack - 384 bytes
  305. topstack     equ this byte
  306.  
  307. PUBLIC TESSINITSTART                     ;required entry point
  308.  
  309. TESSINITSTART:
  310.         assume cs:_TEXT, ds:_TEXT
  311.  
  312. jmp start_init
  313.  
  314. get_cmd_line:
  315.  
  316.         mov  si,80h                      ;Start of command line
  317.         lodsb                            ;Command length
  318.         cmp  al,0                        ;If nothing on command line
  319.         jz   cmd_err                     ;exit
  320. get_1:  lodsb                            ;else get next character
  321.         cmp  al,13                       ;A CR? Then end of line
  322.         jz   cmd_err                     ;with nothing legal. Exit.
  323.         cmp  al,"1" - 1                  ;Is it < ASCII "1"?
  324.         ja   chk_9                       ;No? Check for > "9"
  325.         jmp  short get_1                 ;Yes? get another.
  326. chk_9:  cmp  al,"9" + 1                  ;Above a nine?
  327.         jb   cmd_ok                      ;No? OK - between "1" and "9"
  328.         jmp  short get_1                 ;Yes? Get another
  329. cmd_ok: mov  [TSRminutes],al             ;Is between 1 and 9, so
  330.                                          ;save in TSR ASCII variable
  331.         mov  [minutes],al                ;And in non-resident part too.
  332.         and  ax,0Fh                      ;Convert ASCII to numerical
  333.         mov  cx, ticks_min
  334.         mul  cx                          ;Multiply by ticks_min. (1092)
  335.         mov  di,offset tick_count
  336.         stosw                            ;and initialize count
  337.         stosw                            ;and wait timer value
  338. ;
  339. ;The next few bytes just stuff "# minute(s)." into the command line
  340. ;which will be carried along with the resident program, for MAPMEM
  341. ;or its ilk to see our wait time.
  342. ;
  343.         mov  si,offset signon            ;Signon starts with a CR
  344.         mov  di,80h                      ;which is the value we need.
  345.         movsb                            ;Move 13 to the length byte at 80h
  346.         mov  si,offset minutes           ;Point source at '# minute(s).'
  347.         mov  di,82h                      ;destination at command line
  348.         mov  cx,13                       ;and move 13 bytes
  349. stuff_loop:                              ;looping here
  350.         movsb
  351.         loop stuff_loop
  352.                                          
  353.         clc                              ;then, after clearing carry flag
  354.         ret                              ;exit subroutine
  355. cmd_err:
  356.         stc                              ;Set carry flag
  357.         ret                              ;and return
  358.  
  359. ;
  360. ;  Although I can't find it in the version 1.00 TesSerAct documentation,
  361. ;  TSRCHECKRESIDENT, if it finds the code resident, returns not only
  362. ;  0ffffh in ax but the segment of the resident version in the es register.
  363. ;  This makes it unnecessasry to call multiplex function 4 to find
  364. ;  its location.  I will use that undocumented feature here, but
  365. ;  we should have been told. - Rick Housh
  366. ;
  367.  
  368. start_init:
  369.         mov  si,offset ParkName          ;Check to see if
  370.         mov  di,offset ParkNum           ;resident
  371.         call TSCHECKRESIDENT             ;Returns segment of resident
  372.                                          ;program in es if installed
  373.         or   ax,ax                       ;If already installed
  374.         jnz  is_tsr                      ;then reset or display info msg
  375.         jmp  short do_install            ;else install it
  376. is_tsr: call get_cmd_line                ;If NOT valid command line
  377.         jc   just_checking               ;just display status and exit
  378.         mov  al,[TSRMinutes]             ;else get new value in ASCII
  379.         mov  es:[TSRMinutes],al          ;and put it in resident code
  380.         mov  es:[82h],al                 ;and in resident cmd line for mapmem
  381.         mov  ax,[ticks2wait]             ;Same with ticks to wait
  382.         mov  es:[ticks2wait],ax
  383.         mov  dx,offset tsr_reset         ;Tell em have changed it
  384.         mov  ah,09h
  385.         int  21h
  386.         jmp  short display_time          ;and display new value
  387. just_checking:
  388.         mov  dx,offset already_installed ;Already installed
  389.         mov  ah,09h                      ;and no change, requested so
  390.         int  21h                         ;display status message and exit
  391. display_time:
  392.         mov  al,es:[TSRMinutes]          ;Get minutes from resident code
  393.         mov  [minutes],al                ;move resident value here
  394.         mov  dx,offset auto_time         ;and display
  395.         int  21h                         ;current TSR minute value
  396.  
  397. term_it:
  398.         mov  ax,4c01h                    ;Set error code to 1
  399.         int  21h                         ;and quit
  400.  
  401. do_install:                              ;"Take care of stack early"
  402.         mov  si,offset topstack          ;Because using both,
  403.         mov  di,si                       ;divide stack area
  404.         dec  di                          ;into areas for
  405.         dec  di                          ;PopUpStack and
  406.         sub  si,384                      ;BackGroundStack
  407.         call TSSETSTACK                  ;Two 384 byte stacks
  408.  
  409.         call get_cmd_line                ;Check for valid command line
  410.         jc   cmdline_err                 ;If invalid display message and exit
  411.         call parkit                      ;else attempt to park heads
  412.         jnc  good_park                   ;If able to park say so
  413.         mov  dx,offset bad_park          ;else print problem
  414.         mov  ah,09
  415.         int  21h
  416.         jmp  term_it                     ;and quit with error code
  417. ;
  418. ; display installed message and exit
  419. ;
  420. good_park:
  421.         mov  dx,offset installed
  422.         mov  ah,09                      ;Show that it's installed
  423.         int  21h
  424.         mov  dx,offset miwa_miwa_parwa_stella
  425.         mov  ah,09
  426.         int  21h                         ;and that it tinkles
  427.         mov  dx,offset TESSINITSTART
  428.         mov  bx,1070h                    ;No pop graphics, timer proc,
  429.                                          ; background and main procs only
  430.         mov  ax,0A19h                    ;Alt-LeftShift-P
  431.                                          ;will be hotkey for manual park.
  432.  
  433.         call TSDOINIT
  434.         mov  ax,4c00h                    ;Exit with no error code
  435.         int  21h
  436.  
  437. cmdline_err:
  438.         mov  dx,offset signon
  439.         mov  ah,09
  440.         int  21h                         ;Display the signon message
  441.         jmp  term_it                     ;and quit with error code
  442.  
  443. ;
  444. ;Non-resident data area
  445. ;
  446. ;Following are the message strings for the transient part of the program
  447. ;They do not go resident and are not available to the TSR portion
  448. ;
  449.  
  450. signon  label byte
  451.         db   13,10,'TESSPARK.COM Version 1.0, Copyright (c) '
  452.         db   '1988, TesSeRact(tm) Development Team',13,10
  453.         db   'All Rights Reserved',13,10,10
  454.         db   'Based on Original Code provided by Jim Mischel:',13,10
  455.         db   '   AUTOPARK 1.0  Copyright (c) 1988, Jim Mischel',13,10,10
  456.         db   'TSRPARK additions provided by Rick Housh:',13,10
  457.         db   '   Hotkey instant park, variable auto park intervals,',13,10
  458.         db   '   popup message (at DOS prompt), detection of park',13,10
  459.         db   '   failure on installation, and change of timer while',13,10
  460.         db   '   resident without removal and reinstallation.'
  461.         db   13,10,10
  462.         db   7,'Command line error.  TSRPark NOT loaded.',7,13,10,10
  463.         db   'Syntax: TSRPARK # (Where # is 1 - 9 [minutes] between parks)'
  464.         db   13,10,'$'
  465. already_installed label   byte
  466.         db   13,10,'TSRPARK was already resident',13,10,7,'$'
  467. tsr_reset label   byte
  468.         db   13,10,'TSRPARK was resident and has been reset.',13,10,7,'$'
  469. installed label   byte
  470.         db   13,10,'TSRPARK installed. '
  471. auto_time label   byte
  472.         db   'Auto park every '
  473. minutes db   ' '
  474.         db   ' minute(s).',13,10
  475.         db   'Alt + Left Shift + "P" parks hard disks instantly',13,10,'$'
  476. miwa_miwa_parwa_stella label byte        ;Or "miva" and "parva" if you prefer
  477.         db   'A "tinkle" will sound when heads are parked',13,10,'$'
  478. bad_park label byte    ;BAD PROBLEM, LOTS OF BELLS
  479.         db   13,10,7,'Hard disk error.  Unable to park hard disk.'
  480.         db   13,10,7,'Terminating.',13,10,7,'$'
  481.  
  482. _TEXT ends
  483.  
  484.         END
  485.